﻿@using OJS.Web.Areas.Contests.ViewModels.Contests
@using Resource = Resources.Areas.Contests.Views.ListIndex

@model IEnumerable<ContestViewModel>
@{
    ViewBag.Title = Resource.Title;
}

<ol class="breadcrumb">
    <li><a href="/">@Resource.Home</a></li>
    <li class="active">@Resource.Contests</li>
</ol>

@section Scripts {
    <script src="/Scripts/Contests/list-categories-page.js"></script>
}

<div class="row">
    <div class="col-md-3">
        <h2>@ViewBag.Title</h2>
        @(Html.Kendo().TreeView()
              .Name("contestsCategories")
              .DataTextField("Name")
              .DataSource(dataSource => dataSource
                          .Model(x =>
                          {
                              x.Id("Id");
                              x.HasChildren("HasChildren");
                          })
                          .Read(read => read
                              .Action("ReadCategories", "List", new { area = "Contests" })))
              .Events(x =>
              {
                  x.Select("expander.categorySelected");
                  x.DataBound("expander.onDataBound");
              })
        )
        @if (User.IsAdmin())
        {
            <br />
            <p class="pull-left"><a class="btn btn-primary" href="/Administration/ContestCategories">@Resource.Categories &raquo;</a></p>
            <p class="pull-right"><a class="btn btn-primary" href="/Administration/ContestCategories/Hierarchy">@Resource.Hierarchy &raquo;</a></p>
            <div class="clearfix"></div>
        }
    </div>
    <div class="col-md-9">
        <div id="contestsList">
        </div>
    </div>
</div>

<script>
    var contestsList = $('#contestsList');
    $.get('/Contests/List/ByCategory/', null, function (data) {
        contestsList.append(data);
    });
</script>